package com.carful.xigua.modules.common.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringContextUtil implements ApplicationContextAware {
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.context = applicationContext;
    }

    private static ApplicationContext context;
    public static ApplicationContext getContext() {
        return context;
    }

    public static  <T> T getBean(Class<T> tClass) {
        return context.getBean(tClass);
    }

    public static  <T> T getBean(String name, Class<T> tClass) {
        return context.getBean(name, tClass);
    }
}
